<?php

namespace App\Http\Requests\OperationManagement;

use Illuminate\Foundation\Http\FormRequest;
use App\Http\Requests\BaseRequest;

class GovernmentDeviceRequest extends BaseRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required',
            'device_name' => 'required',
            'device_tag' => 'required',
            'address' => 'required',
            'service_time' => 'required|date',
            'last_time' => 'required|date',
            'next_time' => 'required|date',
            'department_id' => 'required|integer',
            'principal_id' => 'required',
            'phone' => 'required|regex:/^1[345789][0-9]{9}$/'
        ];
    }

    public function messages() 
    {
        return [
            'name.required' => '市政名称不能为空',
            'device_name.required' => '设备名称不能为空',
            'device_tag.required' => '设备标号不能为空',
            'address.required' => '地址不能为空',
            'service_time.required' => '维护时间不能为空',
            'service_time.date' => '维护时间格式不正确',
            'last_time.required' => '上次维护时间不能为空',
            'last_time.date' => '上次维护时间格式不正确',
            'next_time.required' => '下次维护时间不能为空',
            'next_time.date' => '下次维护时间格式不正确',
            'department_id.required' => '负责部门id不能为空',
            'department_id.integer' => '负责部门id只能填写数字',
            'principal_id.required' => '负责人不能为空',
            'phone.required' => '手机号不能为空',
            'phone.regex' => '手机号格式不合法'
        ];
    }

}
